﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using INSTA.GestionEcole.DAL;

namespace INSTA.EcoleGestion.FORMS
{
    public partial class Administration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

           
                    


                }

        protected void ButtonConnexionAdmin(object sender, EventArgs e)
        {
            using (var context = new GestionInstaEntities())
            {
                string login = TextBox1.Text;
                string pass = TextBox2.Text;


                if (login != null && pass != null)
                {



                    int query2 = (from p in context.Administration
                                  where p.Nom == login && p.Password == pass
                                  select p).Count();

                    if (query2 == 0)
                    {
                        Label1.Text = "Errueur d'Authentification";
                        Label1.ForeColor = Color.DarkRed;
                        Label1.Visible = true;

                    }
                    else
                    {
                        var query = from p in context.Administration
                                    where p.Nom == login && p.Password == pass
                                    select p;
                        foreach (var admin in query)
                        {
                            login = admin.Nom;
                            pass = admin.Password;

                        }

                        Response.Redirect("~/AdministrationOutils.aspx");
                    }
                   
        }
            }
        }
    }
}